#include "trap.h"

// logic r type
#define AND_TEST(rs1, rs0, rt1, rt0) \
    lui $t0, rs1; \
    nop; \
    nop; \
    nop; \
    ori	$t0, $t0, rs0; \
    nop; \
    nop; \
    nop; \
    lui $t1, rt1; \
    nop; \
    nop; \
    nop; \
    ori	$t1, $t1, rt0; \
    nop; \
    nop; \
    nop; \
    and $t2, $t0, $t1; 

#define NOR_TEST(rs1, rs0, rt1, rt0) \
    lui $t0, rs1; \
    nop; \
    nop; \
    nop; \
    ori	$t0, $t0, rs0; \
    nop; \
    nop; \
    nop; \
    lui $t1, rt1; \
    nop; \
    nop; \
    nop; \
    ori	$t1, $t1, rt0; \
    nop; \
    nop; \
    nop; \
    nor $t2, $t0, $t1; 

#define OR_TEST(rs1, rs0, rt1, rt0) \
    lui $t0, rs1; \
    nop; \
    nop; \
    nop; \
    ori	$t0, $t0, rs0; \
    nop; \
    nop; \
    nop; \
    lui $t1, rt1; \
    nop; \
    nop; \
    nop; \
    ori	$t1, $t1, rt0; \
    nop; \
    nop; \
    nop; \
    or $t2, $t0, $t1; 

#define XOR_TEST(rs1, rs0, rt1, rt0) \
    lui $t0, rs1; \
    nop; \
    nop; \
    nop; \
    ori	$t0, $t0, rs0; \
    nop; \
    nop; \
    nop; \
    lui $t1, rt1; \
    nop; \
    nop; \
    nop; \
    ori	$t1, $t1, rt0; \
    nop; \
    nop; \
    nop; \
    xor $t2, $t0, $t1; 

// logic i type
#define ANDI_TEST(rs1, rs0, imm) \
    lui $t0, rs1; \
    nop; \
    nop; \
    nop; \
    ori	$t0, $t0, rs0; \
    nop; \
    nop; \
    nop; \
    andi $t2, $t0, imm; 

#define ORI_TEST(rs1, rs0, imm) \
    lui $t0, rs1; \
    nop; \
    nop; \
    nop; \
    ori	$t0, $t0, rs0; \
    nop; \
    nop; \
    nop; \
    ori $t2, $t0, imm; 

#define XORI_TEST(rs1, rs0, imm) \
    lui $t0, rs1; \
    nop; \
    nop; \
    nop; \
    ori	$t0, $t0, rs0; \
    nop; \
    nop; \
    nop; \
    xori $t2, $t0, imm; 

#define LUI_TEST(imm) \
    lui $t2, imm;


// arithmetic r-type
#define ADD_TEST(rs1, rs0, rt1, rt0) \
    lui $t0, rs1; \
    nop; \
    nop; \
    nop; \
    ori	$t0, $t0, rs0; \
    nop; \
    nop; \
    nop; \
    lui $t1, rt1; \
    nop; \
    nop; \
    nop; \
    ori	$t1, $t1, rt0; \
    nop; \
    nop; \
    nop; \
    add $t2, $t0, $t1;

#define ADDU_TEST(rs1, rs0, rt1, rt0) \
    lui $t0, rs1; \
    nop; \
    nop; \
    nop; \
    ori	$t0, $t0, rs0; \
    nop; \
    nop; \
    nop; \
    lui $t1, rt1; \
    nop; \
    nop; \
    nop; \
    ori	$t1, $t1, rt0; \
    nop; \
    nop; \
    nop; \
    addu $t2, $t0, $t1;

#define SUB_TEST(rs1, rs0, rt1, rt0) \
    lui $t0, rs1; \
    nop; \
    nop; \
    nop; \
    ori	$t0, $t0, rs0; \
    nop; \
    nop; \
    nop; \
    lui $t1, rt1; \
    nop; \
    nop; \
    nop; \
    ori	$t1, $t1, rt0; \
    nop; \
    nop; \
    nop; \
    sub $t2, $t0, $t1;

#define SUBU_TEST(rs1, rs0, rt1, rt0) \
    lui $t0, rs1; \
    nop; \
    nop; \
    nop; \
    ori	$t0, $t0, rs0; \
    nop; \
    nop; \
    nop; \
    lui $t1, rt1; \
    nop; \
    nop; \
    nop; \
    ori	$t1, $t1, rt0; \
    nop; \
    nop; \
    nop; \
    subu $t2, $t0, $t1;

#define SLT_TEST(rs1, rs0, rt1, rt0) \
    lui $t0, rs1; \
    nop; \
    nop; \
    nop; \
    ori	$t0, $t0, rs0; \
    nop; \
    nop; \
    nop; \
    lui $t1, rt1; \
    nop; \
    nop; \
    nop; \
    ori	$t1, $t1, rt0; \
    nop; \
    nop; \
    nop; \
    slt $t2, $t0, $t1;

#define SLTU_TEST(rs1, rs0, rt1, rt0) \
    lui $t0, rs1; \
    nop; \
    nop; \
    nop; \
    ori	$t0, $t0, rs0; \
    nop; \
    nop; \
    nop; \
    lui $t1, rt1; \
    nop; \
    nop; \
    nop; \
    ori	$t1, $t1, rt0; \
    nop; \
    nop; \
    nop; \
    sltu $t2, $t0, $t1;

#define MULT_TEST(rs1, rs0, rt1, rt0) \
    lui $t0, rs1; \
    nop; \
    nop; \
    nop; \
    ori	$t0, $t0, rs0; \
    nop; \
    nop; \
    nop; \
    lui $t1, rt1; \
    nop; \
    nop; \
    nop; \
    ori	$t1, $t1, rt0; \
    nop; \
    nop; \
    nop; \
    mult $t0, $t1;

#define MULTU_TEST(rs1, rs0, rt1, rt0) \
    lui $t0, rs1; \
    nop; \
    nop; \
    nop; \
    ori	$t0, $t0, rs0; \
    nop; \
    nop; \
    nop; \
    lui $t1, rt1; \
    nop; \
    nop; \
    nop; \
    ori	$t1, $t1, rt0; \
    nop; \
    nop; \
    nop; \
    multu $t0, $t1;

// arithmetic i-type
#define ADDI_TEST(rs1, rs0, imm) \
    lui $t0, rs1; \
    nop; \
    nop; \
    nop; \
    ori	$t0, $t0, rs0; \
    nop; \
    nop; \
    nop; \
    addi $t2, $t0, imm;

#define ADDIU_TEST(rs1, rs0, imm) \
    lui $t0, rs1; \
    nop; \
    nop; \
    nop; \
    ori	$t0, $t0, rs0; \
    nop; \
    nop; \
    nop; \
    addiu $t2, $t0, imm;

#define SLTI_TEST(rs1, rs0, imm) \
    lui $t0, rs1; \
    nop; \
    nop; \
    nop; \
    ori	$t0, $t0, rs0; \
    nop; \
    nop; \
    nop; \
    slti $t2, $t0, imm;

#define SLTIU_TEST(rs1, rs0, imm) \
    lui $t0, rs1; \
    nop; \
    nop; \
    nop; \
    ori	$t0, $t0, rs0; \
    nop; \
    nop; \
    nop; \
    sltiu $t2, $t0, imm;

// shift
#define SLLV_TEST(rs1, rs0, rt1, rt0) \
    lui $t0, rs1; \
    nop; \
    nop; \
    nop; \
    ori	$t0, $t0, rs0; \
    nop; \
    nop; \
    nop; \
    lui $t1, rt1; \
    nop; \
    nop; \
    nop; \
    ori	$t1, $t1, rt0; \
    nop; \
    nop; \
    nop; \
    sllv $t2, $t1, $t0;

#define SRLV_TEST(rs1, rs0, rt1, rt0) \
    lui $t0, rs1; \
    nop; \
    nop; \
    nop; \
    ori	$t0, $t0, rs0; \
    nop; \
    nop; \
    nop; \
    lui $t1, rt1; \
    nop; \
    nop; \
    nop; \
    ori	$t1, $t1, rt0; \
    nop; \
    nop; \
    nop; \
    srlv $t2, $t1, $t0;

#define SRAV_TEST(rs1, rs0, rt1, rt0) \
    lui $t0, rs1; \
    nop; \
    nop; \
    nop; \
    ori	$t0, $t0, rs0; \
    nop; \
    nop; \
    nop; \
    lui $t1, rt1; \
    nop; \
    nop; \
    nop; \
    ori	$t1, $t1, rt0; \
    nop; \
    nop; \
    nop; \
    srav $t2, $t1, $t0;

#define SLL_TEST(rt1, rt0, sa) \
    lui $t0, rt1; \
    nop; \
    nop; \
    nop; \
    ori	$t0, $t0, rt0; \
    nop; \
    nop; \
    nop; \
    sll $t2, $t0, sa;

#define SRL_TEST(rt1, rt0, sa) \
    lui $t0, rt1; \
    nop; \
    nop; \
    nop; \
    ori	$t0, $t0, rt0; \
    nop; \
    nop; \
    nop; \
    srl $t2, $t0, sa;

#define SRA_TEST(rt1, rt0, sa) \
    lui $t0, rt1; \
    nop; \
    nop; \
    nop; \
    ori	$t0, $t0, rt0; \
    nop; \
    nop; \
    nop; \
    sra $t2, $t0, sa;

// datamove
#define HILO_TEST() \
    nop; \
    nop; \
    nop; \
    mfhi $t0; \
    mflo $t1; \
    nop; \
    nop; \
    nop; \
    mthi $t1; \
    mtlo $t0; 

// memory access
#define SB(data1, data0, base, offset) \
    lui $t0, data1; \
    nop; \
    nop; \
    nop; \
    ori	$t0, $t0, data0; \
    nop; \
    nop; \
    nop; \
    la $t1, base; \
    nop; \
    nop; \
    nop; \
    sb $t0, offset($t1); 

#define SH(data1, data0, base, offset) \
    lui $t0, data1; \
    nop; \
    nop; \
    nop; \
    ori	$t0, $t0, data0; \
    nop; \
    nop; \
    nop; \
    la $t1, base; \
    nop; \
    nop; \
    nop; \
    sh $t0, offset($t1); 

#define SW(data1, data0, base, offset) \
    lui $t0, data1; \
    nop; \
    nop; \
    nop; \
    ori	$t0, $t0, data0; \
    nop; \
    nop; \
    nop; \
    la $t1, base; \
    nop; \
    nop; \
    nop; \
    sw $t0, offset($t1); 

#define LB_TEST(base, offset) \
    la $t3, base; \
    nop; \
    nop; \
    nop; \
    lb $t2, offset($t3); 

#define LH_TEST(base, offset) \
    la $t3, base; \
    nop; \
    nop; \
    nop; \
    lh $t2, offset($t3); \

#define LW_TEST(base, offset) \
    la $t3, base; \
    nop; \
    nop; \
    nop; \
    lw $t2, offset($t3); \
    

#define LBU_TEST(base, offset) \
    la $t3, base; \
    nop; \
    nop; \
    nop; \
    lbu $t2, offset($t3); \
    

#define LHU_TEST(base, offset) \
    la $t3, base; \
    nop; \
    nop; \
    nop; \
    lhu $t2, offset($t3); \








    

